<?php

namespace App\Model\Api;

use App\Model\BaseModel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

class UserTagsCat extends BaseModel
{
    protected $connection = 'api';
    protected $table = "user_tags_cat";

    /**
     * [getShowList 根据分类id 获取显示标签分类]
     */
    public function getShowListById($whereIn = [], $sort='sort', $desc='desc') {
        $res = DB::connection($this->connection)
            ->table($this->table)
            ->where('status', '=', 0)
            ->whereIn('id', $whereIn)
            ->orderBy($sort, $desc)
            ->get()
            ->toArray();
        return $res;
    }

    /**
     * [getShowList 获取显示标签分类]
     */
    public function getShowList() {
        $res = DB::connection($this->connection)
            ->table($this->table)
            ->where('status', '=', 0)
            ->orderBy('sort', 'desc')
            ->get()
            ->toArray();
        return $res;
    }

    /**
     * [getList 获取标签分类]
     */
    public function getList() {
        $res = DB::connection($this->connection)
            ->table($this->table)
            ->orderBy('sort', 'desc')
            ->get()
            ->toArray();
        return $res;
    }

    /**
     * [findById 获取1条]
     * @Author   LING
     * @DateTime 2022-06-07
     * @param    [type]     $id [description]
     * @return   [type]         [description]
     */
    public function findById($id)
    {
        return DB::connection($this->connection)
            ->table($this->table)
            ->find($id);
    }

    public function createUserTagsCat(array $data = []) {
        return curl_request(getKkaudioApiUrl() . '/inner/user/create_tags_cat', $data);
    }

    public function updateUserTagsCat(int $id, array $data = []) {
        return curl_request(getKkaudioApiUrl() . '/inner/user/update_tags_cat', array_merge($data, [ 'id' => $id ]));
    }

    public function delUserTagsCat(int $id) {
        return curl_request(getKkaudioApiUrl() . '/inner/user/del_tags_cat', [ 'id' => $id ]);
    }
}
